﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

	<!-- Brushes -->
	<SolidColorBrush x:Key="RedSolidBrush"
					 Color="#f2835c" />

	<LinearGradientBrush x:Key="BlueGradient"
						 StartPoint="0,0"
						 EndPoint="0,1">
		<GradientStop Offset="0"
					  Color="#b3e1ff" />
		<GradientStop Offset="1"
					  Color="#65b6fc" />
	</LinearGradientBrush>

	<LinearGradientBrush x:Key="BlackGradient"
						 StartPoint="0,0"
						 EndPoint="0,1">
		<GradientStop Offset="0"
					  Color="#0e0e0e" />
		<GradientStop Offset="0.5"
					  Color="#5d5e5d" />
		<GradientStop Offset="1"
					  Color="#0e0e0e" />
	</LinearGradientBrush>

	<LinearGradientBrush x:Key="RedGradient"
						 StartPoint="0,0"
						 EndPoint="0,1">
		<GradientStop Offset="0"
					  Color="#f2835c" />
		<GradientStop Offset="0.5"
					  Color="#e55b2b" />
		<GradientStop Offset="1"
					  Color="#ee6232" />
	</LinearGradientBrush>

	<!-- ScrollBar Style -->
	<LinearGradientBrush x:Key="ThumbBrush"
						 StartPoint="0,0"
						 EndPoint="1,0">
		<GradientStop Offset="0"
					  Color="#5d5e5d" />
		<GradientStop Offset="1"
					  Color="#0e0e0e" />
	</LinearGradientBrush>

	<LinearGradientBrush x:Key="TrackBrush"
						 StartPoint="0,0"
						 EndPoint="1,0">
		<GradientStop Offset="0"
					  Color="#777777" />
		<GradientStop Offset="0.75"
					  Color="#cccccc" />
		<GradientStop Offset="1"
					  Color="#cccccc" />
	</LinearGradientBrush>

	<ControlTemplate x:Key="RBTemplate"
					 TargetType="RepeatButton">
		<Rectangle Fill="Transparent" />
	</ControlTemplate>
	<ControlTemplate x:Key="ThumbTemplate"
					 TargetType="Thumb">
		<Border Background="{TemplateBinding Background}"
				BorderThickness="0" />
	</ControlTemplate>

	<ControlTemplate x:Key="VerticalScrollBarTemplate"
					 TargetType="ScrollBar">
		<Grid>
			<Border Background="{StaticResource TrackBrush}"
					BorderBrush="#999999"
					BorderThickness="1"
					Padding="1">
				<Track x:Name="PART_Track"
					   IsDirectionReversed="True">
					<Track.DecreaseRepeatButton>
						<RepeatButton Command="ScrollBar.PageUpCommand"
									  Template="{StaticResource RBTemplate}" />
					</Track.DecreaseRepeatButton>
					<Track.Thumb>
						<Thumb Template="{StaticResource ThumbTemplate}"
							   Background="{TemplateBinding Background}"
							   BorderThickness="1"
							   BorderBrush="{TemplateBinding BorderBrush}" />
					</Track.Thumb>
					<Track.IncreaseRepeatButton>
						<RepeatButton Command="ScrollBar.PageDownCommand"
									  Template="{StaticResource RBTemplate}" />
					</Track.IncreaseRepeatButton>
				</Track>
			</Border>
		</Grid>
	</ControlTemplate>

	<Style x:Key="ScrollBarStyle"
		   TargetType="ScrollBar">
		<Setter Property="Width"
				Value="16" />
		<Setter Property="Background"
				Value="{StaticResource ThumbBrush}" />
		<Setter Property="BorderBrush"
				Value="#999999" />
		<Setter Property="Template"
				Value="{StaticResource VerticalScrollBarTemplate}" />
	</Style>

	<!-- TreeView[Item] templates -->
	<ControlTemplate x:Key="ScrollViewerTemplate"
					 TargetType="ScrollViewer">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
				<ColumnDefinition Width="20" />
			</Grid.ColumnDefinitions>

			<ScrollContentPresenter Name="PART_ScrollContentPresenter"
									Content="{TemplateBinding Content}"
									ContentTemplate="{TemplateBinding ContentTemplate}"
									CanContentScroll="{TemplateBinding CanContentScroll}"
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
			<ScrollBar Name="PART_VerticalScrollBar"
					   Orientation="Vertical"
					   Style="{StaticResource ScrollBarStyle}"
					   Grid.Column="1"
					   Minimum="0.0"
					   Maximum="{TemplateBinding ScrollableHeight}"
					   ViewportSize="{TemplateBinding ViewportHeight}"
					   Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
					   Cursor="Arrow"
					   Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
		</Grid>
	</ControlTemplate>

	<ControlTemplate x:Key="TreeViewTemplate"
					 TargetType="TreeView">
		<ScrollViewer Background="{TemplateBinding Background}"
					  Focusable="false"
					  CanContentScroll="false"
					  Template="{StaticResource ScrollViewerTemplate}"
					  Padding="{TemplateBinding Padding}"
					  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
			<ItemsPresenter />
		</ScrollViewer>
	</ControlTemplate>

	<DataTemplate x:Key="ItemTemplate">
		<Border Margin="20,0,0,0"
				Padding="3">
			<TextBlock x:Name="TitleText"
					   Text="{Binding XPath=@Title}"
					   VerticalAlignment="Center"
					   Foreground="WhiteSmoke"/>
		</Border>

		<DataTemplate.Triggers>
			<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}"
						 Value="True">
				<Setter Property="Foreground"
						TargetName="TitleText"
						Value="Black" />
			</DataTrigger>
		</DataTemplate.Triggers>
	</DataTemplate>

	<HierarchicalDataTemplate x:Key="ChapterTemplate"
							  ItemsSource="{Binding XPath=Item}"
							  ItemTemplate="{StaticResource ItemTemplate}">
		<StackPanel>
			<Grid>
				<Grid Width="32"
					  Height="32"
					  HorizontalAlignment="Left">
					<Image Source="/Resources/chapter.png" />
					<TextBlock Text="{Binding XPath=@Order}"
							   VerticalAlignment="Center"
							   HorizontalAlignment="Center"
							   FontWeight="Bold"
							   FontSize="16"
							   Foreground="White" />
				</Grid>
				<TextBlock x:Name="TitleText"
						   Text="{Binding XPath=@Title}"
						   VerticalAlignment="Center"
						   FontWeight="Bold"
						   Foreground="{StaticResource RedSolidBrush}"
						   Margin="37,0,0,0" />
			</Grid>
			<ItemsPresenter />
		</StackPanel>

		<DataTemplate.Triggers>
			<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}"
						 Value="True">
				<Setter Property="Foreground"
						TargetName="TitleText"
						Value="Black" />
			</DataTrigger>
		</DataTemplate.Triggers>

	</HierarchicalDataTemplate>

	<HierarchicalDataTemplate x:Key="BookTemplate"
							  ItemTemplate="{StaticResource ChapterTemplate}"
							  ItemsSource="{Binding XPath=Chapter}">
		<StackPanel>
			<DockPanel>
				<Image Source="book.png"
					   DockPanel.Dock="Left"
					   Width="22" />
				<TextBlock Text="{Binding XPath=@Title}"
						   VerticalAlignment="Center"
						   FontWeight="Bold" />
			</DockPanel>
			<ItemsPresenter />
		</StackPanel>
	</HierarchicalDataTemplate>

	<Style x:Key="{x:Type TreeViewItem}"
		   TargetType="TreeViewItem">
		<Setter Property="IsExpanded"
				Value="True" />
		<Setter Property="Padding"
				Value="2,0,10,0" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="TreeViewItem">
					<DockPanel Background="Transparent">
						<Border x:Name="Border"
								DockPanel.Dock="Top"
								Padding="5">
							<ContentPresenter Content="{TemplateBinding Header}"
											  ContentTemplate="{TemplateBinding HeaderTemplate}" />
						</Border>
						<ItemsPresenter />
					</DockPanel>

					<ControlTemplate.Triggers>
						<Trigger Property="IsSelected"
								 Value="True">
							<Setter Property="Background"
									Value="{StaticResource BlueGradient}"
									TargetName="Border" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>